{template 'web/'.$cfg['floder'].'/base_menu'}
<script src="{MODULE_URL}template/resources/js/jquery-ui.min.js"></script>
<div class="top_tab"> 
  <a href="{php echo $this->createWebUrl('market')}" class="layui-btn {if $operation != 'display'}layui-btn-primary{/if}">管理订单营销</a> 
  {if $operation == 'post'}<a href="{php echo $this->createWebUrl('market',array('op'=>'post'))}" class="layui-btn layui-btn-primary">添加订单营销</a>{/if} 
  <a href="{php echo $this->createWebUrl('market',array('op'=>'goodmarket'))}" class="layui-btn {if $operation != 'goodmarket'}layui-btn-primary{/if}">管理商品营销</a> 
  {if $operation == 'goodmarketpost'}<a href="{php echo $this->createWebUrl('market',array('op'=>'goodmarketpost'))}" class="layui-btn">添加订单营销</a>{/if} 
</div>
<style>
.panelbox-head a{ margin-right:10px}
.green{ color:#090}
.orange{ color:#F60}
</style>
{if $operation == 'display'}
<div class="panelbox">
<form action="" method="post" class="layui-form" enctype="multipart/form-data">
  <div class="panelbox-head">
  	<a href="{php echo $this->createWebUrl('market',array('op'=>'post'))}" class="layui-btn layui-btn-small"><i class="layui-icon">&#xe61f;</i> 新增营销活动</a> 拖动内容进行排序
  </div>
  <div class="panelbox-body">
    <div class="layui-form">
      <table class="layui-table">
        <thead>
          <tr>
            <th>序号</th>
            <th>活动标题</th>
            <th>优惠</th>
            <th>对象</th>
            <th>时间</th>
            <th>状态</th>
            <th>备注</th>
            <th style="text-align:right">操作</th>
          </tr>
        </thead>
        <tbody>
        	{loop $list $row}
        	<tr>
              <td><input type="hidden" name="displayorder" value="{$row['id']}" /><span class="order">{$row['displayorder']}</span></td>
              <td>{$row['title']}</td>
              <td>
              满<b>{$row['fee']}</b>元
              {if $row['ftype']==1}
              <b>减</b><span class="orange">{$row['content']}</span>
              {elseif $row['ftype']==2}
              <b>返卡券</b>
              {elseif $row['ftype']==3}
              <b>返红包</b><span class="orange">{$row['content']}</span>
              {elseif $row['ftype']==4}
              <b>获得抽奖</b><span class="orange">{$row['content']}</span>
              {/if}
              </td>
              <td>{if $row['memberlevel']}<span class="label label-danger">会员</span>{else}<span class="label label-info">不限</span>{/if}</td>
              <td>
              	<span class="label label-info">{php echo date("Y/m/d",$row['starttime'])}</span>-<span class="label label-info">{php echo date("m/d",$row['starttime'])}</span>
                
                
              </td>
              <td>{if $row['status']}<span class="label label-success"><i class="fa fa-ok"></i></span>{else}<span class="label label-default"><i class="fa fa-remove"></i></span>{/if}</td>
              <td>{$row['description']}</td>
              <td style="text-align:right">
              	 <a href="{php echo $this->createWebUrl('market',array('op' => 'post', 'id' => $row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a>
          <a href="javascript:deleteContent('{php echo $this->createWebUrl('market',array('op'=>'delete','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a>
              </td>
            </tr>
            {/loop}
        </tbody>
      </table>
    </div>
  </div>
  <div class="panelbox-foot text-right">  <div id="pagecount"></div></div>
  </form>
</div>
<script language="javascript">
var fixHelper = function(e, ui) {    
	ui.children().each(function() {  
		$(this).width($(this).width());   
	});
	return ui;
};
$(".layui-table tbody").sortable({
	helper: fixHelper,
	axis:"y",  
	start:function(e, ui){  
		ui.helper.css({"background":"#F60"});
	},  
	stop:function(e, ui){  
		ui.item.css({"background":"#FFF"});
		updateMove(e, ui);
	},
}).disableSelection(); 

layui.use(['layer', 'laypage', 'element','form'], function(){
	var layer = layui.layer
	,laypage = layui.laypage
	,element = layui.element
	,form = layui.form;
	form.render();
});
function deleteContent(url){
	layer.confirm('确认删除此内容？删除后将不可恢复', {}, function(){
		location.href=url;
	});
}

function updateMove(){
	var temp={};
	$("input[name='displayorder']").each(function(index, element) {
		var val=$(this).val();
        temp[val]=index+1;
    });
	var index2=layer.load(1, {shade: [0.1,'#fff']});
	$.post("{php echo $this->createWebUrl('market',array('op'=>'updateMove'))}",{displayorder:temp},function(returnstr){
		layer.close(index2);
		console.log(returnstr);
		var result=eval("("+returnstr+")");
		if(result.success){
			layer.msg("更新排序成功",{icon:1,time:2000});
			$(".order").each(function(index, element) {
                $(this).text(index+1);
            });
		}else{
			layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
		}
	});
}
</script>
{elseif $operation == 'post'}
<div class="panelbox">
<form action="" method="post" class="layui-form" enctype="multipart/form-data">
<input type="hidden" name="id" value="{php echo $id}" />
  <div class="panelbox-head">{if !$id}添加{else}编辑{/if}</div>
  <div class="panelbox-body">
    <div class="layui-form-item">
        <label class="layui-form-label">活动标题</label>
      <div class="layui-input-block">
        <input type="text" class="layui-input" lay-verify="required" name="title" value="{$item['title']}"/>
        <div class="help-block">店铺名称，请勿重复</div>
      </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开关</label>
      <div class="layui-input-block">
        <input type="checkbox" {if $item['status']==1}checked{/if} value="1" name="status" lay-skin="switch" lay-text="启用|关闭"/>
        <div class="help-block">活动开关</div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">时间</label>
      <div class="layui-input-block">
        {php echo tpl_form_field_daterange('gametime', array('start' => date('Y-m-d', $item['starttime']),'end'=> date('Y-m-d', $item['endtime'])))}
        <div class="help-block"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">营销方式</label>
      <div class="layui-input-block">
        <select name="ftype" class="layui-input" lay-filter="ftype">
          <option value="0">选择营销方式</option>
          <option value="1" {if $item["ftype"]==1}selected{/if}>(付款前)满XX减XX</option>
          <option value="2" {if $item["ftype"]==2}selected{/if}>(付款后)满XX返卡券</option>
          <option value="3" {if $item["ftype"]==3}selected{/if}>(付款后)满XX返红包</option>
          <option value="4" {if $item["ftype"]==4}selected{/if}>(付款后)满XX抽奖</option>
        </select>
        <div class="help-block">营销方式，<strong>付款后</strong>的活动，系统将打印二维码后，客户扫码后获得奖励</div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">营销内容</label>
      <div class="layui-input-block form-inline">
        <div class="input-group">
          <span class="input-group-addon">满</span>
          <input type="text" lay-ignore class="form-control" placeholder="金额" name="fee" value="{$item['fee']}"/>
          <span class="input-group-addon">元</span>
        </div>
        <div class="help-block"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-block">
        <div class="input-group ftypebox" {if $item["ftype"]!=1}style="display:none;"{/if}>
          <span class="input-group-addon">减少</span>
          <input type="text" lay-ignore class="form-control" style="color:#F60" placeholder="金额" name="content[1]" value="{php echo $item['ftype']==1 ? $item['content'] : ''}"/>
          <span class="input-group-addon">元</span>
        </div>
        
        <div class="input-group ftypebox" {if $item["ftype"]!=2}style="display:none;"{/if}>
          <span class="input-group-addon">返卡券</span>
          <input type="text" lay-ignore class="form-control" placeholder="卡券id，用“|”分割" name="content[2]" value="{php echo $item['ftype']==2 ? $item['content'] : ''}"/>
        </div>
        
        <div class="input-group ftypebox" {if $item["ftype"]!=3}style="display:none;"{/if}>
          <span class="input-group-addon">返红包</span>
          <input type="text" lay-ignore class="form-control" placeholder="填写金额" name="content[3]" value="{php echo $item['ftype']==3 ? $item['content'] : ''}"/>
        </div>
        
        <div class="input-group ftypebox" {if $item["ftype"]!=4}style="display:none;"{/if}>
          <span class="input-group-addon">获得</span>
          <select name="gameid" lay-ignore class="form-control">
            <option value="0">选择活动</option>
            {loop $gamelist $row}
            <option value="{$row['id']}" {if $item["gameid"]==$row['id']}selected{/if}>{$row['title']}</option>
            {/loop}
          </select>
          <span class="input-group-addon">抽奖</span>
          <input type="text" lay-ignore class="form-control" placeholder="抽奖次数，填写数字" name="content[4]" value="{php echo $item['ftype']==4 ? $item['content'] : ''}"/>
          <span class="input-group-addon">次</span>
        </div>
        
        <div class="help-block"><b>满减：</b>支持%；<b>卡券：</b>填写微信卡券ID，多个用“|”分割；<b>红包：</b>支持%，范围用“-”，如5-9；<b>抽奖：</b>直接填写数字是次数，可用5|1，则是每5元增加1次抽奖机会；</div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">有效时间</label>
      <div class="layui-input-block">
        <div style="margin-bottom:10px;">
        	<input type="checkbox" name="limitweek[0]" value="0" title="不限" {if !$item['limitweek']}checked{/if}  lay-filter="limitweek"/>
            {php $ary=array("星期一","星期二","星期三","星期四","星期五","星期六","星期日")}
            {php $i=1;}
            {loop $ary $row}
        	<input type="checkbox" name="limitweek[{php echo $i}]" value="{php echo $i}" title="{$row}" {if in_array($i,explode(',',$item['limitweek']))}checked{/if}  lay-filter="limitweek"/>
            {php $i++}
            {/loop}
        </div>
        <div style="margin-bottom:10px;">
        	<input type="checkbox" name="limithour[0]" value="0" title="不限" {if !$item['limithour']}checked{/if}  lay-filter="limithour"/>
            <?php for($i=1; $i<=24;$i++){?>
        	<input type="checkbox" name="limithour[{php echo $i}]" value="{php echo $i}" {if in_array($i,explode(',',$item['limithour']))}checked{/if} title="{php echo $i}点" lay-filter="limithour"/>
            <?php }?>
        </div>
        <div class="help-block">
        	
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">适用人群</label>
      <div class="layui-input-block">
        <input type="checkbox" name="memberlevel[0]" value="0" title="不限" {if !$item['memberlevel']}checked{/if} lay-filter="memberlevel"/>
        {loop $grouptemp $row}
        <input type="checkbox" name="memberlevel[{$row['groupid']}]" value="{$row['groupid']}" {if in_array($row['groupid'],explode(',',$item['memberlevel']))}checked{/if} title="{$row['title']}" lay-filter="memberlevel"/>
        {/loop}
        <div class="help-block"></div>
      </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
      <div class="layui-input-block">
        <input type="text" class="layui-input" name="description" value="{$item['description']}"/>
        <div class="help-block">备注</div>
      </div>
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-block">
        <button type="submit" class="layui-btn col-md-1" lay-submit lay-filter="submitbtn">保存</button>
      </div>
    </div>
  </div>
  </form>
</div>
<script language="javascript">
layui.use(['layer', 'laypage', 'element','form'], function(){
	var layer = layui.layer
	,laypage = layui.laypage
	,element = layui.element
	,form = layui.form;
	form.render();
	form.on('select(ftype)', function(data){
		var val=parseInt(data.value);
		if(val>0){
			$(".ftypebox").eq(val-1).show().siblings().hide();
		}
	});
	form.on('checkbox(memberlevel)', function(data){
		if(data.value=='0'){
			if(data.elem.checked)$("input[name^='memberlevel'][value!='0']").attr("checked",false);
		}else{
			$("input[name^='memberlevel'][value='0']").attr("checked",false);
		}
		form.render('checkbox');
	});
	form.on('checkbox(limitweek)', function(data){
		if(data.value=='0'){
			if(data.elem.checked)$("input[name^='limitweek'][value!='0']").attr("checked",false);
		}else{
			$("input[name^='limitweek'][value='0']").attr("checked",false);
		}
		form.render('checkbox');
	});
	form.on('checkbox(limithour)', function(data){
		if(data.value=='0'){
			if(data.elem.checked)$("input[name^='limithour'][value!='0']").attr("checked",false);
		}else{
			$("input[name^='limithour'][value='0']").attr("checked",false);
		}
		form.render('checkbox');
	});
	
	form.on('submit(submitbtn)', function(data){
		
		var index2=layer.load(1, {shade: [0.1,'#fff']});
		$.post("{php echo $this->createWebUrl('market',array('op'=>'postdata'))}",data.field,function(returnstr){
			layer.close(index2);
			console.log(returnstr);
			var result=eval("("+returnstr+")");
			if(result.success){
				layer.msg("保存成功",{icon:1,time:1000},function(){
					if(data.field.id){
						location.reload();
					}else{
						location.href="{php echo $this->createWebUrl('market')}";
					}
				});
				return false;
			}
			return false;
		});
		return false;
	});
	
});

</script>
{elseif $operation == 'goodmarket'}
<div class="panelbox">
<form action="" method="post" class="layui-form" enctype="multipart/form-data">
  <div class="panelbox-head">
  	<a href="{php echo $this->createWebUrl('market',array('op'=>'goodmarketpost'))}" class="layui-btn layui-btn-small"><i class="layui-icon">&#xe61f;</i> 新增商品营销</a> 
  </div>
  <div class="panelbox-body">
    <div class="layui-form">
      <table class="layui-table">
        <thead>
          <tr>
            <th>活动标题</th>
            <th>优惠</th>
            <th>商品数量</th>
            <th>时间</th>
            <th>状态</th>
            <th>备注</th>
            <th style="text-align:right">操作</th>
          </tr>
        </thead>
        <tbody>
        	{loop $list $row}
        	<tr>
              <td>{$row['title']}</td>
              <td>{$row['discount']}</td>
              <td>{php echo $row['contentid'] ? count(@explode(',',$row['contentid'])) : 0}</td>
              <td style="text-align:center">
              	<span class="label label-info">{php echo date("Y/m/d",$row['starttime'])}</span> <br />|<br /> <span class="label label-info">{php echo date("Y/m/d",$row['endtime'])}</span>
              </td>
              <td>{if $row['status']}<span class="label label-success"><i class="fa fa-ok"></i></span>{else}<span class="label label-default"><i class="fa fa-remove"></i></span>{/if}</td>
              <td>{$row['description']}</td>
              <td style="text-align:right">
              	 <a href="{php echo $this->createWebUrl('market',array('op'=>'goodmarketpost','id'=>$row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a>
          <a href="javascript:deleteContent('{php echo $this->createWebUrl('market',array('op'=>'deletegood','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a>
              </td>
            </tr>
            {/loop}
        </tbody>
      </table>
    </div>
  </div>
  </form>
</div>
<script language="javascript">
layui.use(['layer', 'laypage', 'element','form'], function(){
	var layer = layui.layer
	,laypage = layui.laypage
	,element = layui.element
	,form = layui.form;
	form.render();
});
function deleteContent(url){
	layer.confirm('确认删除此内容？删除后将不可恢复', {}, function(){
		location.href=url;
	});
}
</script>
{elseif $operation == 'goodmarketpost'}
<div class="panelbox">
<form action="" method="post" class="layui-form" enctype="multipart/form-data">
<input type="hidden" name="id" value="{php echo $id}" />
  <div class="panelbox-head">{if !$id}添加{else}编辑{/if}</div>
  <div class="panelbox-body">
    <div class="layui-form-item">
        <label class="layui-form-label">活动标题</label>
      <div class="layui-input-block">
        <input type="text" class="layui-input" lay-verify="required" name="title" value="{$item['title']}"/>
        <div class="help-block">店铺名称，请勿重复</div>
      </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开关</label>
      <div class="layui-input-block">
        <input type="checkbox" {if $item['status']==1}checked{/if} value="1" name="status" lay-skin="switch" lay-text="启用|关闭"/>
        <div class="help-block">活动开关</div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">时间</label>
      <div class="layui-input-block">
        {php echo tpl_form_field_daterange('gametime', array('start' => date('Y-m-d', $item['starttime']),'end'=> date('Y-m-d', $item['endtime'])))}
        <div class="help-block"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">折扣</label>
      <div class="layui-input-block form-inline">
        <input type="text" lay-ignore class="form-control" name="discount" value="{$item['discount']}"/>
        <div class="help-block">内容规则：⑴折扣0-100%；⑵-10，直减10元</div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">选择商品</label>
      <div class="layui-input-block form-inline">
      	<input type="hidden" name="contentid" id="contentid" value="{$item['contentid']}"/>
        <p><button type="button" class="layui-btn" onclick="showGood();">选择商品</button></p>
        
        <div class="help-block"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">有效时间</label>
      <div class="layui-input-block">
        <div style="margin-bottom:10px;">
        	<input type="checkbox" name="limitweek[0]" value="0" title="不限" {if !$item['limitweek']}checked{/if}  lay-filter="limitweek"/>
            {php $ary=array("星期一","星期二","星期三","星期四","星期五","星期六","星期日")}
            {php $i=1;}
            {loop $ary $row}
        	<input type="checkbox" name="limitweek[{php echo $i}]" value="{php echo $i}" title="{$row}" {if in_array($i,explode(',',$item['limitweek']))}checked{/if}  lay-filter="limitweek"/>
            {php $i++}
            {/loop}
        </div>
        <div style="margin-bottom:10px;">
        	<input type="checkbox" name="limithour[0]" value="0" title="不限" {if !$item['limithour']}checked{/if}  lay-filter="limithour"/>
            <?php for($i=1; $i<=24;$i++){?>
        	<input type="checkbox" name="limithour[{php echo $i}]" value="{php echo $i}" {if in_array($i,explode(',',$item['limithour']))}checked{/if} title="{php echo $i}点" lay-filter="limithour"/>
            <?php }?>
        </div>
        <div class="help-block"> </div>
      </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
      <div class="layui-input-block">
        <input type="text" class="layui-input" name="description" value="{$item['description']}"/>
        <div class="help-block">备注</div>
      </div>
    </div>
    
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-block">
        <button type="submit" class="layui-btn col-md-1" lay-submit lay-filter="submitbtn">保存</button>
      </div>
    </div>
  </div>
  </form>
</div>
<style>
.modal_history_top{ padding:0 0 10px 0; border-bottom:1px solid #CCC; margin-bottom:10px}
ul.mhlist{background:#EEE;overflow-y:scroll; margin-right:10px;}
ul.mhlist li{ padding:10px; cursor:pointer; border-bottom:1px solid #CCC; font-size:18px;}
ul.mhlist li:hover,ul.mhlist li.isselect{ background:#009688; color:#FFF;}

ul.goodlist{ width:100%; height:100%;background:#EEE;overflow-y:scroll; padding:10px;}
ul.goodlist li{width:19.5%;display:inline-block; margin:0 0 10px 0; text-align:left;}
ul.goodlist li a{display:block; height:50px; margin-right:10px; background:#FFF; position:relative;}
ul.goodlist li a .img{ float:left; margin-right:5px;}
ul.goodlist li a .img img{ width:50px;height:50px;}
ul.goodlist li a .info{ position:absolute;top:0; right:5px; left:55px;}
ul.goodlist li a .info h3{font-size:12px; margin:0; padding:0; text-align:left; line-height:18px; width:100%; overflow:hidden;}
ul.goodlist li a .info p{font-size:80%;}
ul.goodlist li:active a,ul.goodlist li.isselect a{ background:#F66; color:#FFF;}

</style>
<div id="batchOperation" style="display:none; background:#EEE;">
  <form id="batchOperationform" class="layui-form" action="" style="padding:15px">
    <div class="modal_history_top">
      <div class="secrchinput" style="margin-top:0; float:none">
        <button type="button" onclick="searchgoods()"><i class="fa fa-search"></i></button>
        <input type="text" name="modal_history_txtTopupSeachStr" id="modal_history_txtTopupSeachStr" placeholder="输入单号">
      </div>
    </div>
    <div class="row">
    	<div class="col-md-4">
        	<ul class="mhlist">
            	<li cid='0' onclick="selectPcate(0)">已选</li>
            	{loop $goodcatelist $row}
            	<li cid='{$row['id']}' onclick="selectPcate({$row['id']})">{$row['title']}</li>
                {/loop}
            </ul>
        </div>
        <div class="col-md-8">
        	<ul class="goodlist">
            	
            </ul>
        </div>
        
    </div>
    <div class="text-right"> <button type="button" class="layui-btn modal_selectall">全选</button>  <button type="button" class="layui-btn layui-btn-primary modal_historyboxclosebtn">关闭</button></div>
  </form>
</div>
<script language="javascript">
layui.use(['layer', 'laypage', 'element','form'], function(){
	var layer = layui.layer
	,laypage = layui.laypage
	,element = layui.element
	,form = layui.form;
	form.render();
	form.on('checkbox(limitweek)', function(data){
		if(data.value=='0'){
			if(data.elem.checked)$("input[name^='limitweek'][value!='0']").attr("checked",false);
		}else{
			$("input[name^='limitweek'][value='0']").attr("checked",false);
		}
		form.render('checkbox');
	});
	form.on('checkbox(limithour)', function(data){
		if(data.value=='0'){
			if(data.elem.checked)$("input[name^='limithour'][value!='0']").attr("checked",false);
		}else{
			$("input[name^='limithour'][value='0']").attr("checked",false);
		}
		form.render('checkbox');
	});
	
	form.on('submit(submitbtn)', function(data){
		
		var index2=layer.load(1, {shade: [0.1,'#fff']});
		$.post("{php echo $this->createWebUrl('market',array('op'=>'postgoodata'))}",data.field,function(returnstr){
			layer.close(index2);
			console.log(returnstr);
			var result=eval("("+returnstr+")");
			if(result.success){
				layer.msg("保存成功",{icon:1,time:1000},function(){
					if(data.field.id){
						location.reload();
					}else{
						location.href="{php echo $this->createWebUrl('market',array('op'=>'goodmarket'))}";
					}
				});
				return false;
			}
			return false;
		});
		return false;
	});
	
});
function showGood(){
	var _w=$(document).width()*0.8;
	var _h=$(document).height()*0.8;
	layer.open({
		type: 1,
		title:"选择商品",
		area:[_w+'px',_h+"px"],
		skin: 'layui-layer-rim',
		content:$("#batchOperation").show(),
		success: function(layero, index){
			$("#batchOperationform")[0].reset();
			$(".mhlist , .goodlist").height(_h-200);
			$(".modal_historyboxclosebtn").bind("click",function(){
				layer.close(index);
			})
			$(".modal_selectall").bind("click",function(){
				$(".goodlist li").addClass("isselect");
				$(".goodlist li").each(function(index, element) {
                    var gid=$(this).attr("gid");
					addId(true,gid);
                });;
			})
			selectPcate(0);
		},
		end:function(){
			$("#batchOperation").hide();
			$(".modal_historyboxclosebtn").unbind("click");
		}
	});
}
function selectPcate(id){
	$("#batchOperationform li[cid='"+id+"']").addClass("isselect").siblings().removeClass("isselect");
	var selectid=$("#contentid").val();
	var index2=layer.load(1, {shade: [0.5,'#fff']});
	$.post("{php echo $this->createWebUrl('market',array('op'=>'selectpcate'))}",{cid:id,selectid:selectid},function(returnstr){
		console.log(returnstr);
		layer.close(index2);
		var result=eval("("+returnstr+")");
		$(".goodlist").empty();
		if(result.success){
			var list=result.list;
			if(list.length==0){
				$(".goodlist").text("无更多商品");
				return;
			}
			for(var i=0;i <list.length;i++){
				var temp='<li gid="'+list[i].id+'"';
				temp+=id ? '' : ' class="isselect"';
				temp+='> <A href="javascript:" onclick="chooseGood('+list[i].id+')"><div class="img"><img src="'+list[i].thumb+'" onerror="this.src=\'{MODULE_URL}template/resources/img/002.png\';"></div><div class="info"><h3>'+list[i].title+'</h3><p><span>￥'+list[i].marketprice+'</span></p></div></A></li>';
				$(".goodlist").append(temp);
			}
		}
	});
}
function chooseGood(id){
	var isSelect=false;
	if($(".goodlist li[gid='"+id+"']").hasClass("isselect")){
		isSelect=false;
		$(".goodlist li[gid='"+id+"']").removeClass("isselect");
	}else{
		isSelect=true;
		$(".goodlist li[gid='"+id+"']").addClass("isselect");
	}
	addId(isSelect,id);
}
function addId(type,id){
	var goodids=$("#contentid").val() ? $("#contentid").val().split(","): [];
	var goodAry={};
	for(var i in goodids){
		goodAry[goodids[i]]=goodids[i];
	}
	if(type){
		goodAry[id]=id;
	}else{
		goodAry[id]=0;
	}
	var tempAry=[];
	for(var i in goodAry){
		if(parseInt(goodAry[i]))tempAry.push(goodAry[i]);
	}
	$("#contentid").val(tempAry.join(","));
}
</script>

{/if}